<?php

namespace app\modules\backend\controllers;

use \app\controllers\BaseController as SiteBaseController;

/**
 * 基础
 */
class BaseController extends SiteBaseController
{

    /**
     * 页面布局文件
     */
    public $layout = '@app/views/layouts/backendAjax';

    /**
     * 获取排序字段
     * @return array
     */
    protected function getSort()
    {
        $sortField = $this->get('sort_field', '', 'str');
        return [
            $sortField . ' ' . $this->get('sort_type', '', 'str'),
            'id ' . $this->get('sort_type', '', 'str'),
        ];
    }

    /**
     * 获取每页分页大小
     * @return array|float|int|mixed|string|null
     */
    protected function getPageSize()
    {
        // 获取分页大小默认
        $pageSize = $this->get('page_size',
            \Yii::$app->params['dataLimit'], 'int'
        );
        // 规定最大分页数
        return $pageSize > \Yii::$app->params['maxDataLimit'] ?
            \Yii::$app->params['maxDataLimit'] : $pageSize;
    }

    /**
     * 获取多条操作每次最多操作数
     * @return int|mixed
     */
    protected function getMaxIdCount() {
        return empty(\Yii::$app->params['maxIdCount']) ?
            100 : \Yii::$app->params['maxIdCount'];
    }
}
